<template>
  <div class="dialog_info">
    <div class="tab">
      <span
        v-for="(item, index) in tabTitList"
        :key="index"
        :class="{ activeTab: selectNum == index }"
        class="tabTit"
        @click="change(index)"
      >
        {{ item }}
      </span>
    </div>
    <div v-show="selectNum == 0" style="height:85%"  v-loading="loading1" element-loading-background="rgba(0, 0, 0, 0.8)">
      <div style="padding:10px 0 0 0" class="Ingone">
        <el-form label-width="90px">
          <el-form-item label="原因说明">
            <el-input v-model="hulueSeg" type="textarea" :resize="'none'"  placeholder="请说明忽略原因" />
          </el-form-item>
        </el-form>
        <div class="hulueSureBtn">
          <span class="btnCjfa" @click="hulueSure">确定</span>
        </div>
      </div>
    </div>
    <div v-show="selectNum == 1" v-loading="btnload" element-loading-background="rgba(0, 0, 0, 0.8)" class="dialog_info_title">
      <div class="treeBox">
        <el-tree
          class="treecont"
          ref="tree1"
          node-key="id"
          :data="VillageWarnStaticList"
          show-checkbox
          check-strictly
          :props="defaultProps"
          :expand-on-click-node="false"
          :default-expanded-keys="[checkedKey]"
          :default-checked-keys="[checkedKey]"
          highlight-current
          @check="deptNodeClick"
        />
      </div>
      <div v-loading="loading" element-loading-background="rgba(0, 0, 0, 0.8)" class="formBox">
        <div class="messageTitle">预警信息内容编辑</div>
        <div class="textareaBox">
          <el-input v-model="desc" type="textarea" placeholder="无预警" :resize="'none'" :rows="6" />
        </div>
        <div class="messageTitle">接收人</div>
        <div class="sendtableBox listTables">
          <el-table
            ref="tablelist"
            :data="tableData"
            style="width: 100%;height: 100%;">
            
            <el-table-column type="selection" width="42px" align="center" />
            <el-table-column type="index" label="序号" />
            <el-table-column prop="addvnm" label="政区" />
            <el-table-column prop="name" label="联系人" />
            <el-table-column prop="post" label="职务" />
            <el-table-column prop="phone" label="电话" />
          </el-table>
        </div>
        <div class="hulueSendBtn">
          <span class="btnCjfa" @click="hulueSend">发送</span>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import {
    GetVillageWarnStaticInfo
} from '@/api/zyx.js'
import {
    GetSendPersonByAddvcd,
    GetProviceMessage,
    IngoneWarning,
} from '@/api/xuna.js'
export default {
  props: { 
    fatherMethod: { 
    type: Function,
    default: null
    }
    },
    data() {
        return {
            tabTitList: ['忽略预警信息', '发送预警信息'],
            selectNum: '0',
            data: [],
            defaultProps: {
                children: 'children',
                label: 'label'
            },
            hulueSeg: '',
            parameter: {},
            VillageWarnStaticList: [],
            addvcdName: '',
            addvcd: '610521103212008',
            desc: '',
            tableData: [],
            loading: false,
            checkedKey: '',
            loading1:false,
            btnload:false,
            thirdPageUser:{},
           
        }
    },
    created() {
     // console.log(this.$store.getters.dlgParams.params)
        this.parameter = {
            ...this.$store.getters.dlgParams.params[0]
        };
        this.thirdPageUser = this.$store.getters.thirdPageUser;

    },
    methods: {
        // 忽略短信
        hulueSure() {
            if(!this.hulueSeg){
               this.$message({
                    showClose: true,
                    message: '请说明忽略原因！！！',
                    type: 'warning'
                });
              return;
            }
            let pams = {
                id: this.parameter.ForecastId,
                renson: this.hulueSeg
             };
             let jclj = this.parameter.eventName;
             let urls = ''
             if(jclj=='YJJC'){//监测预警
               urls = '/api/EarlyWarning/IngoneMonitorWarning'
             }else if(jclj=='YJLJ'){//临近预警
               urls = '/api/EarlyWarning/IngoneShortWarning'

             };
             if(!urls){
                 this.$message({
                        showClose: true,
                        message: '无接口地址！！！',
                        type: 'warning'
                    });
                  return;
             };
            this.loading1 = true;
            IngoneWarning(pams,urls).then((res) => {
                this.loading1 = false;
                if (res.isSuccess) {
                    this.$message({
                        message: res.message,
                        type: 'success'
                    })
                  if(this.fatherMethod){
                      this.fatherMethod(jclj);
                  };
                } else {
                    this.$message.error(res.message)
                }
            }).catch(err=>{
              this.loading1 = false;

            })
        },
        hulueSend() {
          let that = this;
          let tablear = this.$refs.tablelist.selection;
       
          let descs = this.desc.trim();
          if(!descs){
             this.$message({
                  showClose: true,
                  message: '预警信息不能为空！！！',
                  type: 'warning'
              });
            return
          }
          if(tablear.length == 0){
             this.$message({
                  showClose: true,
                  message: '请选择接收人！！！',
                  type: 'warning'
              });
            return
          };
          // console.log(this.thirdPageUser)
          if(!this.thirdPageUser.addvcd){
            this.$message({
                  showClose: true,
                  message: '未获取到主系统的登录人addvcd',
                  type: 'warning'
              });
            return;
          }
           let jclj = this.parameter.eventName;
           let typ = '0';
            if(jclj=='YJJC'){
              typ = '2'
            }else if(jclj=='YJLJ'){
              typ = '1'

            }
          let pams={
              "strBegin":this.parameter.rainStart,//
              "strEnd":this.parameter.rainEnd,
              "addvcd": this.thirdPageUser.addvcd || '610000',//   在主系统过来 当前登录人的政区编码
              "message":descs,//   短息信息
              "Type":typ,//  1临近预警 2  监测预警
              "WSWSCD":this.$store.getters.basin,// 流域编码
              "Target_oF_Sms":tablear,//接收人的集合
              "UserId":this.thirdPageUser.userId,//主系统当前登录人的userID
          };
          //console.log(pams);//  http://10.61.10.151:5002/api/Values/Api/GetSMSSendingBySY
         // return;
          that.btnload = true;
          let urls =  "/sendMessage/Values/Api/GetSMSSendingBySY";
          this.$axios.post(urls,pams).then((res) => {
              // console.log(res)
               let dat = res.data;
                that.btnload = false;
               if(res.status==200&&dat.IsSuccess){
                 let msgstr = '信息发送成功！！！';
                    that.$message({
                      showClose: true,
                      message: msgstr,//'信息发送成功！！！',
                      type: 'success'
                    });
                    this.getGetSendPersonByAddvcd();
                    this.getGetProviceMessage();
               }else{ 
                   that.$message({
                      showClose: true,
                      message: '信息发送失败！！！',
                      type: 'warning'
                    });
               }
              
          }).catch(err=>{
              that.btnload = false;
              that.$message({
                      showClose: true,
                      message: '信息发送失败！！！',
                      type: 'warning'
                    });
          });
         

        },
        change(index) {
            this.selectNum = index
            if (index === 1) {
              this.tableData = [];
              this.VillageWarnStaticList = [];
              this.desc = '';
              this.getData();
            }
        },
        deptNodeClick(data) {
           // console.log(data)
            this.$refs.tree1.setCheckedNodes([])
            this.$refs.tree1.setCheckedNodes([{
                id: data.id,
                label: data.label
            }])
            this.checkedKey = data.id
            this.addvcdName = data.label
            this.addvcd = data.id
            this.getGetSendPersonByAddvcd()
            this.getGetProviceMessage()
        },
        // 获取政区树
        getData() {
            GetVillageWarnStaticInfo({
                Addvcd: this.parameter.Ewcode
            }).then((res) => {
                if (res.isSuccess) {
                    this.VillageWarnStaticList = [];
                    this.VillageWarnStaticList.push(res.data);
                    this.checkedKey = this.parameter.Ewcode
                    this.addvcd = this.parameter.Ewcode
                    // this.checkedKey = res.data.id
                    // this.addvcd = res.data.id
                    this.getGetSendPersonByAddvcd()
                    this.getGetProviceMessage()
                } else {
                    this.$message.error(res.message)
                }
            })
        },
        // 获取短信发送人
        getGetSendPersonByAddvcd() {
            this.loading = true;
            this.tableData = [];
            GetSendPersonByAddvcd({
                addvcd: this.addvcd
            }).then((res) => {
                this.loading = false
                if (res.isSuccess) {
                    this.tableData = res.data
                }
            }).catch(err=>{
               this.loading = false;
            })
        },
        // 获取短信内容
        getGetProviceMessage() {
            this.loading = true;
            let jclj = this.parameter.eventName;
            let typ = '';
            if(jclj=='YJJC'){//监测预警   
              typ = '1'
            }else if(jclj=='YJLJ'){//临近预警
              typ = '2'
            }
            const params = {
                addvcd: this.addvcd,
                dtBegin: this.parameter.rainStart,
                dtEnd: this.parameter.rainEnd,
                type: this.parameter.type,
                ewtype:typ,//2 临近预警，1 监测预警
            }
             this.desc = '';
           // console.log(this.parameter)
            GetProviceMessage(params).then((res) => {
                this.loading = false
                if (res.isSuccess && res.data) {
                    this.desc = res.data.message
                }
            }).catch(err=>{
               this.loading = false;
            })
        }

    }
}
</script>

<style lang="less" scoped>
	.tab {
		border-bottom: 1px solid #335875;
		padding-bottom: 15px;
		height: auto;
		overflow: hidden;
	}
   .treecont{
     height: 100%;
     margin-right: 10px;
   }
	.el-tree,
	/deep/.el-tree-node__content:hover,
	.el-upload-list__item:hover,
	/deep/.el-tree--highlight-current .el-tree-node.is-current>.el-tree-node__content {
		//background: rgba(14, 81, 133, 0.75);
    background: linear-gradient(90deg, #00EAFF 0%, rgba(1,39,85,0) 100%);
	}

	.dialog_info {
		padding-top: 15px;
		height: 100%;

		.dialog_info_title {
			// height: 85%;
			display: -webkit-flex;
			display: flex;

			.treeBox {
				width: 25%;
				height: 100%;
			}

			.formBox {
				width: 75%;
				height: calc(100% - 90px);

				.messageTitle {
					width: 100%;
					line-height: 48px;
					padding-left: 20px;
					box-sizing: border-box;
					border: 1px solid #2e4378;
					margin-bottom: 10px;
					box-shadow: 0 0 0 1px #2e4378, inset 0 0 0.9375rem #31467d;
				}
			}
		}

	}

	/deep/ .el-tree-node__label {
		color: #fff;
	}

	.Ingone {
		height: 100%;
		position: relative;

		/deep/ .el-textarea__inner {
			height: 400px;
		}

		.hulueSureBtn {
			text-align: right;
			margin-top: 20px;
			position: absolute;
			bottom: 0;
			right: 0;

			span {
				padding: 5px 20px;
			}
		}

	}

	.hulueSendBtn {
		text-align: right;
		margin-top: 15px;
		span {
			padding: 5px 20px;
		}
	}
  .sendtableBox{
      height: 280px;
    }
</style>
